Search


📜 [專欄新文章] Parity 錢包合約漏洞
✍️ Peter Lai
  • Share this:


📜 [專欄新文章] Parity 錢包合約漏洞
✍️ Peter Lai
📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium
還記得今年 7 月 Parity 錢包合約被找到漏洞,結果駭客偷走了將近 150,000 個以太幣,會發生是因為智能合約的 callback 裡使用了 delegatecall(msg.data),這個函數會呼叫 data 中的函數並將 msg.sender 設為元呼叫函數的地址,駭客利用這一點呼叫了 initWallet,這時你們可能會以為 Parity 應該有在 initWallet 設置條件阻擋駭客就不能呼叫,結果竟然是沒有!所以駭客就成功並改變合約的擁有者,最後再把以太幣轉走,細節的部分可以看這篇文章。

Parity 也在幾天後修復了這個問題,修復的方式就是在 init* 函數加上 only_uninitialized modifier 判斷,當 m_numOwners > 0 時這個函數就不能使用,這時應該會想說不會再有漏洞了吧,畢竟智能合約能操作以太幣,誰知道……

就在前幾天發布了新 issue 說他不小心刪除了錢包的合約,因為只有合約的擁有者可以刪除,那麼他到底怎麼刪除合約?可以看到錢包合約被刪除前共有兩筆交易,第一筆交易呼叫 initWallet 並將合約的擁有者設為自己。

function initWallet(address[] _owners, uint _required, uint _daylimit) only_uninitialized { initDaylimit(_daylimit); initMultiowned(_owners, _required);}

交易結果:

Function: initWallet(address[] _owners, uint256 _required, uint256 _daylimit)MethodID: 0xe46dcfeb[0]:0000000000000000000000000000000000000000000000000000000000000060[1]:0000000000000000000000000000000000000000000000000000000000000000[2]:0000000000000000000000000000000000000000000000000000000000000000[3]:0000000000000000000000000000000000000000000000000000000000000001[4]:000000000000000000000000ae7168deb525862f4fee37d987a971b385b96952

第二筆交易呼叫了 kill 函數,而 kill 函數呼叫了 suicide (selfdestruct 函數的別稱,功能是將合約程式從區塊鏈移除,並將合約剩餘的以太幣轉給參數的位置),錢包的程式就從區塊鏈上移除了。

function kill(address _to) onlymanyowners(sha3(msg.data)) external { suicide(_to);}

交易結果:

Function: kill(address _to)MethodID: 0xcbf0b0c0[0]:000000000000000000000000ae7168deb525862f4fee37d987a971b385b96952

因為很多使用這個錢包的合約引入位置都寫死導致很多合約不能運作,在 Polkadot 裡第 451 行就將錢包合約地址寫死:

address constant _walletLibrary = 0x863df6bfa4469f3ead0be8f9f2aae51c91a907b4;

因為所有邏輯判斷都在錢包合約中,所以其他相依於錢包合約的現在以太幣都被凍結,且看起來像這樣 (無法提款):

contract Wallet { function () payable { Deposit(...) }}

Parity 官方還在了解可行的解決方案,如果想查詢自己有沒有被影響可以到這個網站。

參考

Security Alert - Parity Technologies

https://hackernoon.com/parity-wallet-hack-2-electric-boogal…

Parity 錢包合約漏洞 was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.

👏 歡迎轉載分享鼓掌


Tags:

About author
not provided
We have regular meeting twice per month on discussing blockchain technology, smart contracts and DApps development! We would love to have you join us!
View all posts